package com.kai.steering.data.service.entity.domainObject;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.kai.steering.data.service.entity.dto.KnowledgeQueryDTO;
import com.kai.steering.data.service.entity.po.Knowledge;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import java.util.Arrays;
import java.util.Date;

import lombok.*;
import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <pre>
 * 知识点 Do对象
 * </pre>
 *
 * @author kai
 * @date 2022-02-23
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
@ToString
@EqualsAndHashCode(callSuper = false)
@ApiModel(value = "KnowledgeDO对象", description = "知识点业务实体")
public class KnowledgeDO implements Serializable {
    private static final long serialVersionUID = 1L;

    /**
     * 知识点id
     */
    private String knowledgeId;
    /**
     * 知识点名
     */
    private String knowledgeName;
    /**
     * 知识点信息
     */
    private String knowledgeIntroduce;
    /**
     * 创建时间
     */
    private Date creationDate;
    /**
     * 管理员id或者用户id
     */
    private String founder;
    /**
     * 上级知识点id
     */
    private String knowledgeSuperior;
    /**
     * 级别
     */
    private Integer level;
    /**
     * 存在0删除1
     */
    @TableLogic
    private Integer usable;
    /**
     * 删除日期
     */
    private Date deleteDate;
    /**
     * 下级知识点
     */
    private List<KnowledgeDO> childs;

    public KnowledgeDO(KnowledgeQueryDTO knowledgeQueryDTO) {
        BeanUtil.copyProperties(knowledgeQueryDTO,this);
    }

    public KnowledgeDO(Knowledge knowledge) {
        converKnowledgeDO(knowledge);

    }

    public KnowledgeDO(String knowledgeId) {
        this.knowledgeId=knowledgeId;
    }

    public KnowledgeDO converKnowledgeDO(Knowledge knowledge) {
        this.knowledgeId=knowledge.getKnowledgeId();
        this.knowledgeName=knowledge.getKnowledgeName();
        this.knowledgeIntroduce=knowledge.getKnowledgeIntroduce();
        this.creationDate=knowledge.getCreationDate();
        this.founder=knowledge.getFounder();
        this.knowledgeSuperior=knowledge.getKnowledgeSuperior();
        this.level=knowledge.getLevel();
        this.usable=knowledge.getUsable();
        this.deleteDate=knowledge.getDeleteDate();
        this.childs=null;
        return this;
    }
    public static List<KnowledgeDO> converKnowledgeDO(String KnowledgeIdS){
        List<KnowledgeDO> collect = Arrays.asList(StringUtils.splitByWholeSeparator(KnowledgeIdS, ",")).stream().filter(s -> !s.isEmpty()).map(s -> {
            return new KnowledgeDO(s);
        }).collect(Collectors.toList());
        return collect;
    }
}